/*****************************************************************************************
This file is a part of Arise library.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

Arise Engine		KeyAction.cpp

					E-mail:		arise_engine@mail.ru

					Origin by:	DK Engine 0.019,
								dev (avon.dn.ua@gmail.com), Agressor (agress0r@mail.ru)

created:			03.01.2004
last changes:		27.02.2008
*****************************************************************************************/
#include "stdafx.h"


KeyAction::KeyAction(int global_key_id)
{
	m_is_pressed	= false;
	m_num_actions	= 0;
	m_counter		= 0;
	m_key_id		= global_key_id;
}

KeyAction::~KeyAction()
{
}


void KeyAction::AddAction(void action())
{
	FUNCTION_POINTER fp = &action;
	m_actions.push_back(fp);
	m_actions[m_num_actions++] = &action;
}


void KeyAction::Update(bool is_key_pressed)
{	
	if(m_actions.empty()) return;

	if(is_key_pressed && !m_is_pressed)
	{
		FUNCTION_POINTER fp = m_actions[m_counter++];
		(*fp)();
				
		if(m_counter == m_num_actions) m_counter = 0;
		m_is_pressed = true;	
	}
	if(!is_key_pressed) m_is_pressed = false;
}


void KeyAction::Release()
{
}
